<template>
  <div>
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="80px"
      style="width: 500px; margin: 2px"
    >
      <el-form-item label="设备编码" prop="equipmentCoding">
        <el-input v-model="form.equipmentCoding"></el-input>
      </el-form-item>
      <el-form-item label="原厂编号" prop="originalNum">
        <el-input v-model="form.originalNum"></el-input>
      </el-form-item>
      <el-form-item label="设备名称" prop="equipmentName">
        <el-input v-model="form.equipmentName"></el-input>
      </el-form-item>
      <el-form-item label="设备位置" prop="equipmentLocaId">
        <el-select
          v-model="form.equipmentLocaId"
          placeholder="请选择设备位置"
          style="width: 419px"
        >
          <el-option label="1号电梯" value="1"></el-option>
          <el-option label="2号电梯" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备类型" prop="deviceType">
        <el-select
          v-model="form.deviceType"
          placeholder="请选择设备类型"
          style="width: 419px"
        >
          <el-option label="视频监控系统" value="1"></el-option>
          <el-option label="消防系统" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="详细位置" prop="detailedLocation">
        <el-input v-model="form.detailedLocation"></el-input>
      </el-form-item>
      <el-form-item label="设备型号" prop="equipmentModel">
        <el-input v-model="form.equipmentModel"></el-input>
      </el-form-item>
      <el-form-item label="设备品牌" prop="equipmentBrand">
        <el-input v-model="form.equipmentBrand"></el-input>
      </el-form-item>
      <el-form-item label="购买日期" prop="purchaseDate">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.purchaseDate"
            style="width: 419px"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="使用日期" prop="useDate">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.useDate"
            style="width: 419px"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="维护时间" prop="startTime">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.startTime"
            style="width: 419px"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="维护周期" prop="mainteCycle">
        <el-input v-model="form.mainteCycle"></el-input>
      </el-form-item>
      <el-form-item label="维护部门" prop="mainteDepartId">
        <el-select
          v-model="form.mainteDepartId"
          placeholder="请选择维护部门"
          style="width: 419px"
        >
          <el-option label="视频监控系统" value="1"></el-option>
          <el-option label="消防系统" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="维护人员" prop="personnelId">
        <el-select
          v-model="form.personnelId"
          placeholder="请选择维护人员"
          style="width: 419px"
        >
          <el-option label="张三" value="1"></el-option>
          <el-option label="李四" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button style="background-color: green; color: white" @click="add"
          >保存</el-button
        >
        <el-button style="color: green" @click="list">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { addEquipmentLedger } from "@/api/assetManage/EquipmentLedger";
export default {
  data() {
    return {
      form: {
        equipmentCoding: "",
        originalNum: "",
        equipmentName: "",
        equipmentLocaId: "",
        deviceType: "",
        detailedLocation: "",
        equipmentModel: "",
        equipmentBrand: "",
        purchaseDate: "",
        useDate: "",
        startTime: "",
        mainteCycle: "",
        mainteDepartId: "",
        personnelId: "",
      },
      rules: {
        equipmentCoding: [
          { required: true, message: "请输入设备编号", trigger: "blur" },
        ],
        originalNum: [
          { required: true, message: "请输入原厂编号", trigger: "blur" },
        ],
        equipmentName: [
          { required: true, message: "请输入设备名称", trigger: "blur" },
        ],
        equipmentLocaId: [
          { required: true, message: "请选择设备位置", trigger: "change" },
        ],
        deviceType: [
          { required: true, message: "请选择设备类型", trigger: "change" },
        ],
        detailedLocation: [
          { required: true, message: "请输入详细位置", trigger: "blur" },
        ],
        equipmentModel: [
          { required: true, message: "请输入设备型号", trigger: "blur" },
        ],
        equipmentBrand: [
          { required: true, message: "请输入设备品牌", trigger: "blur" },
        ],
        purchaseDate: [
          { required: true, message: "请选择购买日期", trigger: "change" },
        ],
        useDate: [
          { required: true, message: "请选择使用日期", trigger: "change" },
        ],
        startTime: [
          { required: true, message: "请选择开始维护时间", trigger: "change" },
        ],
        mainteCycle: [
          { required: true, message: "请输入维护周期", trigger: "blur" },
        ],
        mainteDepartId: [
          { required: true, message: "请选择维护部门", trigger: "change" },
        ],
        personnelId: [
          { required: true, message: "请选择维护人员", trigger: "change" },
        ],
      },
    };
  },
  methods: {
    //添加
    add() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          addEquipmentLedger(this.form).then((res) => {
            if (res.data) {
              this.$message({
                message: "添加成功",
                type: "success",
              });
              this.$router.push("/assetManage/ledger");
            } else {
              this.$message.error("添加失败");
              return;
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //跳转
    list() {
      this.$router.push("/assetManage/ledger");
    },
  },
  created() {},
};
</script>
<style>
</style>